package cn.com.xy.sms.sdk.number;

import cn.com.xy.sms.sdk.Iservice.OnlineUpdateCycleConfigInterface;
import cn.com.xy.sms.sdk.Iservice.XyCallBack;
import cn.com.xy.sms.sdk.constant.Constant;
import cn.com.xy.sms.sdk.dex.DexUtil;
import cn.com.xy.sms.sdk.log.LogManager;
import cn.com.xy.sms.sdk.util.BaseRunnable;
import cn.com.xy.sms.sdk.util.CallBackState;

/* IMOO-9 likuangkuang 20161014 start */
public class UpgradeEmbedRunnable extends BaseRunnable {
    private static BaseRunnable mBaseRunnable = null;

    public static BaseRunnable getInstance() {
        synchronized (UpgradeEmbedRunnable.class) {
            if (mBaseRunnable == null) {
                mBaseRunnable = new UpgradeEmbedRunnable();
            }
        }

        return mBaseRunnable;
    }

    private UpgradeEmbedRunnable() {
        mExecuteInterval = DexUtil.getUpdateCycleByType(OnlineUpdateCycleConfigInterface.TYPE_OTA_EMBED_NUMBER_CYCLE,
                Constant.week);
    }

    @Override
    public void execute() {
        ParseNumberManager.upgradeEmbedNumber(new XyCallBack() {

            @Override
            public void execute(Object... obj) {
                int status = (Integer) obj[0];
                if (status == CallBackState.HAS_DATA) {
                    String version = obj[1].toString();
                    LogManager.e(Constant.TAG, "current version:" + version);
                } else {
                    // TODO if error, trigger next upgrade or just log
                    LogManager.e(Constant.TAG, obj[2].toString());
                }
            }
        });
    }
}
/* IMOO-9 likuangkuang 20161014 start */